package com.hspedu.map_;

import java.util.HashMap;
import java.util.Map;

/**
 * @author DL5O
 * @version 1.0
 */
@SuppressWarnings("all")
public class MapMethod {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("邓超",new Book("",100));//OK
        map.put("邓超","孙俪");//替换
        map.put("王宝强","马蓉");//OK
        map.put("宋喆","马蓉");//OK
        map.put("刘令博",null);//OK
        map.put(null,"刘亦菲");//OK
        map.put("鹿晗","关晓彤");//OK

        System.out.println("====修改前====\n"+"map=" + map);

        //remove:根据键删除映射关系
        map.remove(null);
        //删除后
        System.out.println("====修改前====\nmap="+map);

        //get：根据键获取值
        Object val = map.get("鹿晗");
        System.out.println("val=" + val);//val=关晓彤找到 鹿晗对应的key

        //size：获取元素个数
        System.out.println("k-v=" + map.size());//5

        //isEmpty:判断是否为空
        System.out.println(map.isEmpty());//F

        //clear:清空
        map.clear();
        System.out.println("map=" + map);

        //containKey:查找键是否存在
        System.out.println(map.containsKey("ywl"));//false
        map.put("ywl",null);//啊啊啊啊啊 我没有对象
        System.out.println(map.containsKey("ywl"));//true
    }
}

class Book{
    private String name;
    private int num;

    public Book(String name, int num) {
        this.name = name;
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}
